﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace NF_Base
{
    public class MessageBoxShow
    {
        #region - win32 -
        
        [DllImport("user32.dll", EntryPoint = "AnimateWindow")]
        private static extern bool AnimateWindow(IntPtr handle, int ms, int flags);
        private const Int32 AW_HOR_POSITIVE = 0x00000001;
        private const Int32 AW_HOR_NEGATIVE = 0x00000002;
        private const Int32 AW_VER_POSITIVE = 0x00000004;
        private const Int32 AW_VER_NEGATIVE = 0x00000008;
        private const Int32 AW_CENTER = 0x00000010;
        private const Int32 AW_HIDE = 0x00010000;
        private const Int32 AW_ACTIVATE = 0x00020000;
        private const Int32 AW_SLIDE = 0x00040000;
        private const Int32 AW_BLEND = 0x00080000;

        #endregion

        private static Form frm = null;
        private static Timer tr = new Timer();

        /// <summary>
        /// LODE
        /// </summary>
        static void frm_Load(object sender, EventArgs e)
        {
            AnimateWindow(frm.Handle, 300, AW_SLIDE | AW_VER_POSITIVE);

            tr.Interval = 2000;
            tr.Tick += tr_Tick;
            tr.Start();
        }

        /// <summary>
        /// 提示语显示
        /// </summary>
        /// <param name="meg">提示语</param>
        public static void Alert(string meg)
        {
            frm = new Form();
            frm.SuspendLayout();

            frm.TransparencyKey = Color.White;
            frm.Opacity = 0.6;
            frm.ShowIcon = false;
            frm.FormBorderStyle = FormBorderStyle.None;

            frm.ShowInTaskbar = false;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.BackColor = Color.Black;
            frm.Width = meg.Length * 20;
            frm.Height = 21;
            frm.AutoSize = false;
            frm.AutoSizeMode = AutoSizeMode.GrowOnly;
            frm.TopMost = true;

            frm.Load += frm_Load;
            frm.FormClosing += frm_FormClosing;

            Label lbl = new Label();
            lbl.Text = meg;
            lbl.Dock = DockStyle.Fill;
            lbl.Font = new Font(@"微软雅黑", 12F);
            lbl.ForeColor = Color.White;
            lbl.BackColor = Color.Transparent;
            lbl.AutoSize = true;
            lbl.Location = new Point(10, 10);

            frm.Controls.Add(lbl);
            frm.ShowDialog();
        }

        /// <summary>
        /// 关闭
        /// </summary>
        static void frm_FormClosing(object sender, FormClosingEventArgs e)
        {
            AnimateWindow(frm.Handle, 300, AW_HIDE | AW_SLIDE | AW_VER_NEGATIVE);
        }


        /// <summary>
        /// 倒计时
        /// </summary>
        static void tr_Tick(object sender, EventArgs e)
        {
            frm.Close();
            tr.Stop();
        }


    }
}
